{include file="common/head"}
<link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
<script src="/static/flatpickr/flatpickr.min.js"></script>
<head>
    <title>库存记录</title>

    <style>
        .form-control {
            width: initial;
            display: inline-block;
        }
    </style>
</head>

<body>
    <div class="container-fluid">

        <form action="/wh/wh_bill" method="post">
            <div class="row" id="query_bar" style="height: 50px;line-height: 50px;">
                <div class="col-2" style="text-align: left;line-height: 50px;font-size: 2rem;">
                    出入库查询
                </div>

                <div class="col">
                    <label for="type">类别:
                        <select id="type" name="type" class="form-control" style="width:80px;">
                            <option value="">所有</option>
                            <option value="1" {if 1==$type} selected {/if}>入库单</option>
                            <option value="2" {if 2==$type} selected {/if}>出库单</option>
                        </select>
                    </label>

                    <label for="type">产品:
                        <select id="goods_id" name="goods_id" class="form-control">
                            <option value="">所有</option>
                            {foreach $goods_list as $kv}
                            <option value="{$kv['id']}" {if $goods_id==$kv['id']}selected{/if}>{$kv['name']}</option>
                            {/foreach}
                        </select>
                    </label>

                    <label for="status">状态:
                        <select id="status" name="status" class="form-control" style="width:80px;">
                            <option value="">全部</option>
                            {foreach $status_arr as $k=>$v}
                            <option value="{$k}" {if $k==$status} selected {/if}>{$v}</option>
                            {/foreach}
                        </select>
                    </label>

                    <label for="sdate">日期：</label>
                    <input class="form-control" type="text" value="{$sdate}" id="sdate" name="sdate" placeholder="开始日期" style="width:120px;"/>

                    <label for="sdate"></label>
                    <input class="form-control" type="text" value="{$edate}" id="edate" name="edate" placeholder="结束日期" style="width:120px;"/>

                    <label for="bill_no">关键字：
                        <input class="form-control" type="text" value="{$bill_no}" id="bill_no" name="bill_no"
                            placeholder="单据编号 bill_no" />
                    </label>

                    <button type="button" class="btn btn-warning query" style="vertical-align: middle;">
                        <span class="bi-search"></span>
                    </button>

                </div>

            </div>
        </form>


        <table class="table table-sm table-hover table-striped table-bordered">
            <thead class="table-info">
                <th>序号</th>
                <th>单据编号</th>
                <th>类别</th>
                <th>件数</th>
                <th>产品数</th>
                <th>录入人</th>
                <th>录入时间</th>
                <th>状态</th>
                <th>审核人</th>
                <th>审核时间</th>
                <th>

                </th>
            </thead>
            <tbody>
                {foreach $list['data'] as $k=>$kv}
                <tr>
                    <td>{$k+1}</td>
                    <td>{$kv['bill_no']}</td>
                    <td>{$kv['type_name']}</td>
                    <td>{$kv['pack_qty']}</td>
                    <td>{$kv['qty']}</td>
                    <td>{$kv['creater_name']}</td>
                    <td>{$kv['create_time']}</td>
                    <td>{$kv['status_name']}</td>
                    <td>{$kv['check_name']}</td>
                    <td>{$kv['check_time']}</td>
                    <td>

                        <button type="button" class="btn btn-sm btn-info list" id="{$kv['id']}">
                            <span class="bi-list"></span>
                        </button>

                        {if $kv['status']==1}
                        <button type="button" class="btn btn-sm btn-primary check" id="{$kv['id']}">
                            <span class="bi-check"></span>
                        </button>

                        <button type="button" class="btn btn-sm btn-danger trash" id="{$kv['id']}">
                            <span class="bi-trash"></span>
                        </button>
                        {/if}

                    </td>
                </tr>
                {/foreach}

            </tbody>
        </table>
        {include file="common/pagination"}
    </div>

</body>

<script type="text/javascript">
        flatpickr("#sdate,#edate", {weekNumbers:false});
    $(document).ready(function () {

        $(".query").on('click', function () {
            var index = layer.load(0, { shade: false }); //0代表加载的风格，支持0-2
            var cid = $("#customer_id").val();
            var order_no = $("#order_no").val();
            var sdate = $("#sdate").val();
            var edate = $("#edate").val();

            $("form").submit();
            layer.close(index);
        })

        $(".list").on('click', function () {
            var id = $(this).attr('id');
            layer.open({
                type: 2,
                title: '出入库明细表',
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['900px', '600px'],
                content: '/wh/wh_list/id/' + id
            });
        })

        $(".check").on('click', function () {
            var oid = $(this).attr('id');
            layer.confirm('请注意：单据一旦确认，对应产品库存将会更新!!!<br/>请在确认之前，仔细检查订单产品规格及数量？', {
                btn: ['已经确认好了', '再检查一下'] //按钮
            }, function () {

                $.post("/wh/wh_check", { id: oid, status: 2 }, function (res) {
                    if (res.code) {
                        //layer.open({content:'订单已确认!'});
                        location.reload();
                    } else {
                        layer.open({ content: '失败!' });
                    }
                });

            }, function () {
                layer.msg('取消操作!');
            });
        })

        $(".trash").on('click', function () {
            var id = $(this).attr('id');
            layer.confirm('确认把本单据丢进垃圾筒吗？', {
                btn: ['Yes', 'No'] //按钮
            }, function () {

                $.post("/wh/wh_cancel", { table: 'wh_bill', id: id }, function (res) {
                    console.log(res.msg)
                    if (res.code) {
                        location.reload();
                    } else {
                        layer.open({ 'content': res.msg });
                    }

                });

            }, function () {
                layer.msg('取消操作!');
            });

        })


    })
</script>


</body>

</html>